package its_models.expert_model;

import database_handler.DatabaseManager;
import its_models.expert_model.expert_help_util.StrategyGraphUnit;
import its_models.expert_model.expert_help_util.StepsMatrix;
import model_controller.ControlLayer;

public class ExpertModel {

    public ExpertModel(ControlLayer inputController){
        logicalRulesExpert = new LogicalRulesExpert(inputController);
        // 20091029 phrase 2 start
        //solvedPuzzleExpert = new LogicalRulesExpert(inputController);
        // 20091029 phrase 2 start
        Controller = inputController;
    }

    public boolean getDefiniteValueSet(int inputIndexX, int inputIndexY){
        return logicalRulesExpert.getDefiniteValueSet(inputIndexX, inputIndexY);
    }
    public Integer[] getDifficultyRange(int inputDifficultyIndex){
        return logicalRulesExpert.getDifficultyRange(inputDifficultyIndex);
    }

    // 20091112 phrase2 start
    public String getGameDifficulty(){
        return logicalRulesExpert.getGameDifficulty();
    }
    // 20091112 phrase2 end

    public int getNumCellsUnsolved(){
        return logicalRulesExpert.getNumCellsUnsolved();
    }

    // 20091017 phrase2 start
    public String getRuleUsed(int inputIndexX, int inputIndexY){
        return logicalRulesExpert.getRuleUsed(inputIndexX, inputIndexY);
    }
    public void setRuleUsed(int inputIndexX,int inputIndexY, String rule){
       logicalRulesExpert.setRuleUsed(inputIndexX, inputIndexY, rule);
    }
    // 20091017 phrase2 end
    
    public void removeDefiniteValue(int inputIndexX, int inputIndexY){
        logicalRulesExpert.removeDefiniteValue(inputIndexX, inputIndexY);
        //solvedPuzzleExpert.removeDefiniteValue(inputIndexX, inputIndexY);
    }

    public void setDifficultyLevel(String inputDifficultyLevel){
        logicalRulesExpert.setDifficultyLevel(inputDifficultyLevel);
        //solvedPuzzleExpert.setDifficultyLevel(inputDifficultyLevel);
    }
    public void setGivenCellDefiniteValue(int inputIndexX, int inputIndexY, int inputCellValue){
        logicalRulesExpert.setGivenCellDefiniteValue(inputIndexX, inputIndexY, inputCellValue);
        //solvedPuzzleExpert.setGivenCellDefiniteValue(inputIndexX, inputIndexY, inputCellValue);
    }
    public void setNumGivenCells(int inputNumGivenCells){
        logicalRulesExpert.setNumGivenCells(inputNumGivenCells);
        //solvedPuzzleExpert.setNumGivenCells(inputNumGivenCells);
    }
    public void setCellDefiniteValue(int inputIndexX, int inputIndexY, int inputCellValue){
        logicalRulesExpert.setCellDefiniteValue(inputIndexX, inputIndexY, inputCellValue);
        //solvedPuzzleExpert.setCellDefiniteValue(inputIndexX, inputIndexY, inputCellValue);
    }
    /* 20091017 phrase 2 start */
    /*public void setRulesRanking(ArrayList<Integer> inputRulesRanking){
        logicalRulesExpert.setRulesRanking(inputRulesRanking);
    }*/
    /* 20091017 phrase 2 end*/

    public int[] getInvolvedValue(StrategyGraphUnit involvedCell){
        return logicalRulesExpert.getValueInvolved(involvedCell);
    }

    /* for hits procedure */
    public String getSGSolvingProcedure(StrategyGraphUnit inputSolvingUnit){
     return logicalRulesExpert.getSGSolvingProcedure(inputSolvingUnit);
    }
    public String getNSSolvingProcedure(StrategyGraphUnit inputSolvingUnit){
     return logicalRulesExpert.getNSSolvingProcedure(inputSolvingUnit);
    }
    public String getHSSolvingProcedure(StrategyGraphUnit inputSolvingUnit){
     return logicalRulesExpert.getHSSolvingProcedure(inputSolvingUnit);
    }
    public String getIRSolvingProcedure(StrategyGraphUnit inputSolvingUnit, int[] valuesInvolved){
     return logicalRulesExpert.getIRSolvingProcedure(inputSolvingUnit, valuesInvolved);
    }
    public String getNPSolvingProcedure(StrategyGraphUnit inputSolvingUnit, int[] valuesInvolved){
     return logicalRulesExpert.getNPSolvingProcedure(inputSolvingUnit, valuesInvolved);
    }
    public String getHPSolvingProcedure(StrategyGraphUnit inputSolvingUnit, int[] valuesInvolved){
     return logicalRulesExpert.getHPSolvingProcedure(inputSolvingUnit, valuesInvolved);
    }

    // 20100111
        public String getSGSolvingProcedureInChinese(StrategyGraphUnit inputSolvingUnit){
     return logicalRulesExpert.getSGSolvingProcedureInChinese(inputSolvingUnit);
    }
    public String getNSSolvingProcedureInChinese(StrategyGraphUnit inputSolvingUnit){
     return logicalRulesExpert.getNSSolvingProcedureInChinese(inputSolvingUnit);
    }
    public String getHSSolvingProcedureInChinese(StrategyGraphUnit inputSolvingUnit){
     return logicalRulesExpert.getHSSolvingProcedureInChinese(inputSolvingUnit);
    }
    public String getIRSolvingProcedureInChinese(StrategyGraphUnit inputSolvingUnit, int[] valuesInvolved){
     return logicalRulesExpert.getIRSolvingProcedureInChinese(inputSolvingUnit, valuesInvolved);
    }
    public String getNPSolvingProcedureInChinese(StrategyGraphUnit inputSolvingUnit, int[] valuesInvolved){
     return logicalRulesExpert.getNPSolvingProcedureInChinese(inputSolvingUnit, valuesInvolved);
    }
    public String getHPSolvingProcedureInChinese(StrategyGraphUnit inputSolvingUnit, int[] valuesInvolved){
     return logicalRulesExpert.getHPSolvingProcedureInChinese(inputSolvingUnit, valuesInvolved);
    }

    /* only for testing */
    // 20091019 phrase2 start
    public StepsMatrix applyLogicalRules(){
        return logicalRulesExpert.applyLogicalRules();
    }
    // 20091019 phrase2 start
    public StrategyGraphUnit[][] solvePuzzle(){

        // 20091029 phrase 2 start
        //Controller.setTextLearnerStepsMsgBox("in logicalruleExpert has poss value before" + logicalRulesExpert.getStrategyUnit(1, 0).getNumOfPossValues()+ "\n");

        LogicalRulesExpert solvedPuzzleExpert = new LogicalRulesExpert(Controller);
        solvedPuzzleExpert.copy(logicalRulesExpert);
        // 20091029 phrase 2 end
        // 20091017 phrase2 start
        /*LogicalRulesExpert solvedPuzzleExpert2 = new LogicalRulesExpert(logicalRulesExpert);
        CellValuePossibilityUnit[][] solvedPuzzle = solvedPuzzleExpert2.solvePuzzle();
        if(solvedPuzzleExpert2.getNumCellsUnsolved()!=0){

            dbManager.recordError(this.getClass().getName().toString(), "Puzzle cannot be solved", DateTime.getTimestamp());
        }
        return solvedPuzzle;*/
        // 20091017 phrase2 end

        StrategyGraphUnit[][] solvedPuzzle = solvedPuzzleExpert.solvePuzzle();
        logicalRulesExpert.setStepsDepthMatrix(solvedPuzzleExpert.getStepsDepthMatrix());
        // for testing
        //Controller.setTextLearnerStepsMsgBox("in logicalruleExpert has poss value" + logicalRulesExpert.getStrategyUnit(1, 0).getNumOfPossValues()+ "\n");
        //Controller.setTextLearnerStepsMsgBox("in solvedPuzzle has poss value" + solvedPuzzleExpert.getStrategyUnit(1, 0).getNumOfPossValues()+ "\n");
        StrategyGraphUnit checkUnit = Controller.getStrategyUnit(1, 0);
        //Controller.setTextLearnerStepsMsgBox("in Controoler has poss value" + checkUnit.getNumOfPossValues()+ "\n");
        return solvedPuzzle;
    }

    // 20091029 phrase2 start
    public void recordStepsMatrix(int stepCount){
        logicalRulesExpert.recordStepsMatrix(stepCount);
    }
    public void recordSkillsMatrix(){
         logicalRulesExpert.recordSkillsMatrix();
    }
    // testing
    public StrategyGraphUnit getStrategyUnit(int indexX, int indexY){
        return logicalRulesExpert.getStrategyUnit(indexX, indexY);
    }
   // 20091029 phrase2 end

    /* LogicalRulesExpert  for tracking data with learner input */
    private LogicalRulesExpert logicalRulesExpert;
    // 20091017 phrase2 start  - comment
    /* LogicalRulesExpert  for solving the puzzle */
    //private LogicalRulesExpert solvedPuzzleExpert;
    private DatabaseManager dbManager;
    // 20091017 phrase2 end
    private ControlLayer Controller;
    /* LogicalRulesExpert  for solving the puzzle */
    //private LogicalRulesExpert solvedPuzzleExpert;





}
